/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
function ListNode(val?:number) {
    this.val = val;
    this.next = null;
}

function removeElements<T>(head:T[] , val: Number): T[] {
    if (!head) return false;
    let newHead = new ListNode();
    newHead.next = head;
    let tmpNode = newHead;

    while (tmpNode.next) {
        if (tmpNode.next.val == val) {
            tmpNode.next = tmpNode.next.next;
        } else {
            tmpNode = tmpNode.next;
        }
    }
    return newHead.next
};

//removeElements([1, 2, 6, 3, 4, 5, 6], 5)
